var request = require("request");

request("https://www.baidu.com", function (error, response, body) {
    console.log(body);

    // 成功error = null
    if (error) {
        console.log(error);
    } else {
        console.log(response.statusCode);
    }


});


request({
    url:    'http://cnodejs.org/',   // 请求的URL
    method: 'GET',                   // 请求方法
    headers: {                       // 指定请求头
        'Accept-Language': 'zh-CN,zh;q=0.8',         // 指定 Accept-Language
        'Cookie': '__utma=4454.11221.455353.21.143;' // 指定 Cookie
    }
}, function (error, response, body) {
    if (!error && response.statusCode == 200) {
        console.log(body) // 输出网页内容
    }
});


var data = {
    url :'',
    form:{key:'value'}
}

request.post(data,function (err ,response ,body) {

});

console.log("---------------------代理-------------------------------------下边开始测试代理");

var opt = {
    proxy:'http://171.211.127.8:36371',
    url:'https://www.ipip.net/'
};

request(opt , function (err ,response ,data) {
   if(err){
       throw err;
   } else{
       console.log(data);
   }
});

// {'proxy':'http://username:password@url:port'}
// headers: {
//     'Proxy-Authentication':'Base ' + new Buffer('username:password').toString('base64')
// }